#include <iostream>
#include <nlohmann/json.hpp>
//json _finalResult
//vector<WebPage> _pages
using json = nlohmann::json;
using namespace std;
class webpage {
public:
    std::string _doc;
    int _docId;
    std::string _docTitle;
    std::string _docUrl;
    std::string _docContent;
    std::string _docSummary;
};

void generateJson(const vector<webpage>& _pages,json& _finalResult){
    for(const auto& page : _pages){
        json pageJson;
        //pageJson["_doc"] = page._doc;
        //pageJson["_docId"] = page._docId;
        pageJson["_docTitle"] = page._docTitle;
        pageJson["_docUrl"] = page._docUrl;
        //pageJson["_docContent"] = page._docContent;
        pageJson["_docSummary"] = page._docSummary;

        _finalResult.push_back(pageJson);
    }
}

/*json getResult(){
    return _finalResult;
}*/


int main() {
    std::vector<webpage> webpages;

    webpage page1;
    page1._doc = "这是文档1";
    page1._docId = 1;
    page1._docTitle = "文档标题1";
    page1._docUrl = "https://example.com/doc1";
    page1._docContent = "文档内容1";
    page1._docSummary = "文档摘要1";

    webpage page2;
    page2._doc = "这是文档2";
    page2._docId = 2;
    page2._docTitle = "文档标题2";
    page2._docUrl = "https://example.com/doc2";
    page2._docContent = "文档内容2";
    page2._docSummary = "文档摘要2";

    webpages.push_back(page1);
    webpages.push_back(page2);

    json _finalResult;//test

    generateJson(webpages,_finalResult);

    //json jsonObj=getResult();
    // 输出 JSON 对象
    std::cout << _finalResult.dump() << std::endl;

    return 0;
}
